package com.smt.core.servlet;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;

/**
 * Created with IntelliJ IDEA.
 * User: Jose
 * Date: 11/05/12
 * Time: 0:51
 * To change this template use File | Settings | File Templates.
 */
public class SMTServletConfig implements ServletConfig
{
    private static SMTServletConfig  servletConfig = null;

    private SMTServletConfig()
    {

    }

    private  HttpServletRequest request;

    @Override
    public String getServletName() {

        return request.getServletContext().getServletContextName();  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public ServletContext getServletContext() {
        return request.getServletContext();  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public String getInitParameter(String s) {
        return request.getServletContext().getInitParameter(s);  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public Enumeration<String> getInitParameterNames() {
        return request.getServletContext().getInitParameterNames();  //To change body of implemented methods use File | Settings | File Templates.
    }

    public static void createInstace()
    {
        if(servletConfig != null)
        {
            synchronized (SMTServletConfig.class)
            {

                if(servletConfig == null) servletConfig = new SMTServletConfig();
            }

         }
    }

    public static SMTServletConfig getServletConfig() {
        createInstace();
        return servletConfig;
    }

    public void setRequest(HttpServletRequest request) {
        this.request = request;
    }
}
